package com.atguigu.srb.core.controller.api;

import com.atguigu.srb.core.pojo.entity.Lend;
import com.atguigu.srb.core.result.R;
import com.atguigu.srb.core.service.LendService;
import com.atguigu.srb.core.service.impl.LendServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/core/lend")
@Api(tags = "标的管理")
@Slf4j
public class WebLendController {
    @Autowired
    private LendService lendService = new LendServiceImpl();

    @GetMapping("/list")
    public R getLendList() {
        List<Lend> lendList = lendService.getLendList();
        return R.ok().data("list", lendList);
    }

    @GetMapping("/show/{id}")
    public R show(@PathVariable("id") Long lendId) {
        Map<String, Object> lendDetail = lendService.getLendDetail(lendId);
        log.info("获取标的信息--->" + lendDetail);
        return R.ok().data("lendDetail", lendDetail);
    }

    @ApiOperation(value = "计算投资收益")
    @GetMapping("/getInterestCount/{investAmount}/{yearRate}/{totalMonth}/{returnMethod}")
    public R getInterestCount(@PathVariable("investAmount") @ApiParam("投资金额") BigDecimal investAmount,
                              @PathVariable("yearRate") @ApiParam("年化收益") BigDecimal yearRate,
                              @PathVariable("totalMonth") @ApiParam("投资期数") Integer totalMonth,
                              @PathVariable("returnMethod") @ApiParam("还款方式") Integer returnMethod
    ) {

      BigDecimal interestCount   = lendService.getInterestCount(investAmount,yearRate,totalMonth,returnMethod);

        return R.ok().data("interestCount",interestCount);
    }

}
